﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WHC.Hotel.BLL;
using WHC.Hotel.Entity;
using WHC.OrderWater.Commons;

namespace WHC.Hotel.UI.Report
{
    public partial class KFConsumptionReport : BaseForm
    {
        public KFConsumptionReport()
        {
            InitializeComponent();
        }

        private void InitDictItem()
        {
            this.txtInType.Items.Clear();
            this.txtInType.Items.Add(new CListItem("按房间号", "r.RoomNo"));
            this.txtInType.Items.Add(new CListItem("按宾客姓名", "c.Name"));
            this.txtInType.Items.Add(new CListItem("按宾客姓名", "c.Name"));
            this.txtInType.Items.Add(new CListItem("按宾客来源", "c.Source"));
            this.txtInType.Items.Add(new CListItem("按公司名称", "c.CompanyName"));
            this.txtInType.Items.Add(new CListItem("按手工单号", "r.OrderNo"));
            this.txtInType.SelectedIndex = 0;

            this.txtSearchType.Items.Clear();
            this.txtSearchType.Items.Add(new CListItem("按结账单号", "r.BillNumber"));
            this.txtSearchType.Items.Add(new CListItem("按房间号", "r.RoomNo"));
            this.txtSearchType.Items.Add(new CListItem("按宾客姓名", "c.Name"));
            this.txtSearchType.Items.Add(new CListItem("按宾客姓名", "c.Name"));
            this.txtSearchType.Items.Add(new CListItem("按宾客来源", "c.Source"));
            this.txtSearchType.Items.Add(new CListItem("按公司名称", "c.CompanyName"));
            this.txtSearchType.Items.Add(new CListItem("按手工单号", "r.OrderNo"));
            this.txtSearchType.SelectedIndex = 0;

            this.txtStatus.Items.Clear();
            this.txtStatus.Items.Add(new CListItem("离店宾客", ""));
            this.txtStatus.Items.Add(new CListItem("结账宾客", CheckStatus.已结账.ToString()));
            this.txtStatus.Items.Add(new CListItem("挂账宾客", CheckStatus.挂账.ToString()));
            this.txtStatus.Items.Add(new CListItem("免费宾客", CheckStatus.免费.ToString()));
            this.txtStatus.Items.Add(new CListItem("退单宾客", CheckStatus.退单.ToString()));
            this.txtStatus.Items.Add(new CListItem("签单宾客", CheckStatus.签单.ToString()));
            this.txtStatus.SelectedIndex = 0;
        }

        private void KFConsumptionReport_Load(object sender, EventArgs e)
        {
            InitDictItem();

            this.winGridView1.ProgressBar = this.toolStripProgressBar1.ProgressBar;
            this.winGridView1.AppendedMenu = this.contextMenuStrip1;

            this.winGridView2.ProgressBar = this.toolStripProgressBar1.ProgressBar;
            this.winGridView2.AppendedMenu = this.contextMenuStrip2;

            this.dtStart.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
            this.dtEnd.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));

        }

        private void BindInShopData()
        {
            SearchCondition condition = new SearchCondition();
            CListItem item = this.txtInType.SelectedItem as CListItem;
            if (item != null)
            {
                condition.AddCondition(item.Value, this.txtInContent.Text, SqlOperator.Like);
            }
            if (this.chkPartTime.Checked)
            {
                condition.AddCondition("r.IsPartTime", 1, SqlOperator.Equal);
            }

            string filter = condition.BuildConditionSql(DatabaseType.SqlServer);

            DataTable dt = BLLFactory<Customer>.Instance.GetConsumptionDetailReport(filter);
            this.winGridView1.DataSource = dt.DefaultView;
            this.winGridView1.PrintTitle = Portal.gc.gAppUnit + " -- " + "在店宾客消费明细报表";
        }
        private void BindOutShopData()
        {
            SearchCondition condition = new SearchCondition();
            CListItem item = this.txtSearchType.SelectedItem as CListItem;
            if (item != null)
            {
                condition.AddCondition(item.Value, this.txtContent.Text, SqlOperator.Like);
            }

            CListItem checkStatusItem = this.txtStatus.SelectedItem as CListItem;
            if (checkStatusItem != null)
            {
                condition.AddCondition("b.CheckStatus", checkStatusItem.Value, SqlOperator.Equal);
            }
            condition.AddCondition("b.CreateDate", this.dtStart.Value.ToString(), SqlOperator.MoreThanOrEqual)
                .AddCondition("b.CreateDate", this.dtEnd.Value.ToString(), SqlOperator.LessThanOrEqual);

            string filter = condition.BuildConditionSql(DatabaseType.SqlServer);

            DataTable dt = BLLFactory<Customer>.Instance.GetBillConsumptionDetailReport(filter);
            this.winGridView2.DataSource = dt.DefaultView;
            this.winGridView2.PrintTitle = Portal.gc.gAppUnit + " -- " + "离店宾客消费明细报表";
        }

        private void btnInSearch_Click(object sender, EventArgs e)
        {
            BindInShopData();
        }

        private void txtInContent_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnInSearch_Click(null, null);
            }
        }

        private void btnOutSearch_Click(object sender, EventArgs e)
        {
            BindOutShopData();
        }

        private void txtStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            btnOutSearch_Click(null, null);
        }

        private void txtContent_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnOutSearch_Click(null, null);
            }
        }

        private void menu_InRefresh_Click(object sender, EventArgs e)
        {
            BindInShopData();
        }

        private void menu_OutRefresh_Click(object sender, EventArgs e)
        {
            BindOutShopData();
        }

    }
}
